const fs = require('fs')
const path = require('path')
const writeStream = fs.createWriteStream(path.resolve(process.cwd(),'./logs/access.log'),{flags:'a'})

const accessLog = function(req){
    const time = new Date();
    const data = req.headers['user-agent']
    writeStream.write(`${time.getTime()}---${req.method}---${req.url}---${data}\n`)
}
writeStream.on('error',(err)=>{
    console.log(err);
    console.log('日志出错了');
})

module.exports = accessLog